package com.wedimob.slideshare.bo;

import java.net.URI;
import java.net.URL;

public class Medium extends AbstractBO<Medium> {

    private MediumType type;
    private String label;
    private URL url;
    private URI path;
    private String extension;

    public Medium(URL url) {
        super();
        this.url = url;
    }

    public Medium(String label, URL url, URI path) {
        super();
        this.label = label;
        this.url = url;
        this.path = path;
    }

    public String getLabel() {
        return label;
    }

    public URL getUrl() {
        return url;
    }

    public MediumType getType() {
        return type;
    }

    public URI getPath() {
        return path;
    }

    public URI getFilePath() {
        try {
            return new URI(path + "/" + label
                    + (extension == null ? "" : "." + extension));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
        

    public String getExtension() {
        return extension;
    }

    public void setExtension(String extension) {
        this.extension = extension;
        if (extension.contains("jpeg") || extension.contains("jpg")
                || extension.contains("png") || extension.contains("gif")
                || extension.contains("bmp"))
            type = MediumType.PICTURE;

        if (extension.contains("mp4") || extension.contains("avi")
                || extension.contains("wma") || extension.contains("3gp"))
            type = MediumType.VIDEO;

        if (extension.contains("flv") || extension.contains("webm"))
            type = MediumType.FLASH;

        if (extension.contains("mp3"))
            type = MediumType.SOUND;

        if (extension.contains("pdf"))
            type = MediumType.PDF;

        if (extension.contains("htm"))
            type = MediumType.HTML;
    }
}
